package com.gongj.annon;

import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.stereotype.Component;

//@Component
public class MyBeanDefinitionRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor {

	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
		System.out.println("执行 BeanDefinitionRegistryPostProcessor 的 postProcessBeanFactory");


	}

	@Override
	public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {

		System.out.println("执行 BeanDefinitionRegistryPostProcessor 的 postProcessBeanDefinitionRegistry");

		RootBeanDefinition rootBeanDefinition =new RootBeanDefinition(MyBeanDefinitionRegistryPostProcessor2.class,null);
		//注册 BeanDefinition
		//如果对应的 Bean 已经注册且在配置中配置了 bean 不允许被覆盖，
		//则抛出异常,默认是 true，也就是允许覆盖
		registry.registerBeanDefinition("myBeanDefinitionRegistryPostProcessor2",rootBeanDefinition);
	}
}
